<template>
  <div class="list" ref="wrapper">
    <div>
      <div class="area">
        <div class="title border-top-bottom">当前城市</div>
        <div class="button-list">
          <div class="button-wrapper">
            <div class="button">温州</div>
          </div>
        </div>
      </div>
      <div class="area">
        <div class="title border-top-bottom">热门城市</div>
        <div class="button-list">
          <div
            class="button-wrapper"
            v-for="(item, index) of hotcities"
            :key="index"
          >
            <div class="button">{{ item.name }}</div>
          </div>
        </div>
      </div>
      <div class="area" v-for="(item, key) of ddd" :key="key" :ref="key">
        <div class="title border-top-bottom">{{ key }}</div>
        <div class="item-list">
          <div
            class="item"
            v-for="inneritem of item"
            :key="inneritem.id"
          >
            {{ inneritem.name }}
          </div>
        </div>
      </div>
      <!-- <div class="area">
        <div class="title border-top-bottom">A</div>
        <div class="item-list">
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
        </div>
      </div>
      <div class="area">
        <div class="title border-top-bottom">B</div>
        <div class="item-list">
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
          <div class="item">澳洲</div>
        </div>
      </div> -->
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";
import { isEmptyObject } from "@/utils";

export default {
  name: "citylist",
  props: {
    hotcities: Array,
    cities: Object,
    letter: String,
  },
  data() {
    return {
      ddd: {},
    };
  },
  // created() {
  //   cities().then((res) => {
  //     this.data = res.data.total.cities;
  //     console.log(res, "1111");
  //     this.$nextTick(() => {
  //       this.scroll = new BScroll(this.$refs.wrapper, {});
  //     });
  //   });
  // },
  watch: {
    // cities(val){
    //   console.log(val,'valvalval');
    // }
    cities: {
      handler(val) {
        console.log(val, "valvalval");
        if (!isEmptyObject(val)) {
          this.ddd = val;
          this.$nextTick(() => {
            this.scroll = new BScroll(this.$refs.wrapper, {});
          });
        }
      },
      deep: true,
      immediate: true,
    },
    letter() {
      if (this.letter) {
        const element = this.$refs[this.letter][0];
        console.log(element);
        this.scroll.scrollToElement(element);
      }
    },
  },
  methods: {
    
  },
  mounted() {
    // this.$nextTick(() => {
    //     this.scroll = new BScroll(this.$refs.wrapper, {})
    //   })
  },
};
</script>

<style lang="scss" scoped>
.list {
  position: absolute;
  top: 86px;
  left: 0;
  bottom: 0;
  right: 0;
  background-color: #efefef;
  overflow: hidden;
  .title {
    line-height: 22px;
    background-color: #eee;
    color: #666;
    padding-left: 10px;
    font-size: 13px;
    text-align: left;
  }
  .border-top-bottom {
    :before {
      border-color: #ccc;
    }
    :after {
      border-color: #ccc;
    }
  }
  .button-list {
    padding: 5px 30px 5px 5px;
    overflow: hidden;
    background: #fff;
    .button-wrapper {
      float: left;
      width: 33.33%;
      .button {
        margin: 5px;
        border: 1px solid #ccc;
        border-radius: 3px;
        font-size: 13px;
      }
    }
  }
  .item-list {
    .item {
      line-height: 38px;
      padding-left: 10px;
      color: #666;
      text-align: left;
      font-size: 13px;
      border-bottom: 1px solid #eee;
      background: #fff;
    }
  }
}
</style>